package com.hu.zhcc.shiro.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.dao.TOrderMapper;
import com.hu.zhcc.shiro.entity.bo.TOrder;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class TOrderServiceImpl implements TOrderService {

    @Autowired
    private TOrderMapper tOrderMapper;

    @Override
    public int insertSelective(TOrder record) {
        return tOrderMapper.insertSelective(record);
    }

    @Override
    public int deleteByPrimaryKey(Integer hId) {
        return tOrderMapper.deleteByPrimaryKey(hId);
    }
    @Override
    public TOrder selectByPrimaryKey(Integer hId) {
        return tOrderMapper.selectByPrimaryKey(hId);
    }

    @SneakyThrows
    @Override
    public Page<TOrder> findToList(int pageIndex, int num, String value) {
        PageHelper.startPage(pageIndex,num);
        List<TOrder> tOrderList = tOrderMapper.selectByPrimaryName(value);
        PageInfo<TOrder> pageInfo = new PageInfo<>(tOrderList);
        return new Page<TOrder>(pageInfo.getTotal(),tOrderList);
    }

    @Override
    public Page<TOrder> findTo(int pageIndex, int num, String value) {
        PageHelper.startPage(pageIndex,num);
        List<TOrder> tOrderList = tOrderMapper.selectByPrimary(value);
        PageInfo<TOrder> pageInfo = new PageInfo<>(tOrderList);
        return new Page<TOrder>(pageInfo.getTotal(),tOrderList);
    }

    @Override
    public int updateByPrimaryKeySelective(TOrder record) {
        return tOrderMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public Page<TOrder> select(int pageIndex, int num, String value) {
        PageHelper.startPage(pageIndex,num);
        List<TOrder> tOrderList = tOrderMapper.select(value);
        PageInfo<TOrder> pageInfo = new PageInfo<>(tOrderList);
        return new Page<TOrder>(pageInfo.getTotal(),tOrderList);
    }

    @Override
    public Page<TOrder> selectNoun(int pageIndex, int num, String value, Map map) {
        PageHelper.startPage(pageIndex,num);
        List<TOrder> tOrderList = null;
//        if (value.equals("b")) {
//            Date now = new Date();
//            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//            String format = dateFormat.format(now);
//
//            Calendar calendar = new GregorianCalendar();
//
//            calendar.setTime(new Date());
//
//            calendar.add(Calendar.DATE,-2);
//
//            String date2= dateFormat.format(calendar.getTime());
//
//        } else
            if (value.equals("c")) {
            tOrderList = tOrderMapper.selectNuon1(map);
        } else if (value.equals("d")) {
            tOrderList = tOrderMapper.selectNuon2(map);
        }
        PageInfo<TOrder> pageInfo = new PageInfo<>(tOrderList);
        return new Page<TOrder>(pageInfo.getTotal(),tOrderList);
    }

    @Override
    public TOrder selectId(Integer id) {
        return tOrderMapper.selectId(id);
    }

    @Override
    public TOrder se(TOrder record) {
        return tOrderMapper.se(record);
    }
}
